//所有路由相关的代码都放在这个文件
const express=require('express');
// const router1 = require('./router1');
// console.log(express)

const  router2=express.Router();


const  common=require('../utis/common')

router2.get('/home',(req,res)=>{
     res.send({name:'home',age:100,sex:'男' ,plays:'router2'})    
})

router2.get('/news',(req,res)=>{
    res.send({name:'news',age:100,sex:'女',plays:'router2'})
   
})


//  url= http://localhost:3000/books?id=xxxxx  获取get请求的动态参    req.query
router2.get('/books',(req,res)=>{
    console.log(req.query)

    res.send({name:'books',age:100,sex:'女',...req.query,plays:'router2'})
   
})

//动态路由2     url= http://localhost:3000/users/000    获取get请求过来的参数 req.params
router2.get('/users/:id',(req,res)=>{
    console.log(req.params)
    res.send({name:'users',...req.params,plays:'router2'})
})



//动态路由多个参数  
router2.get('/users/:id/young/:names',(req,res)=>{
    console.log(req.params)
    res.send({name:'youngusers',...req.params,plays:'router2'})
})


// post 请求    获取动态参数  需要借用第三方插件 body-parser    数据在req.body身上
router2.post('/post',(req,res)=>{
    console.log(req.body)
    res.send({name:'post',method:'post请求',...req.body,plays:'router2'})
})


router2.get('/zs',common.zs)



//导出 
module.exports =router2;




